<?php
namespace Api\Domain;
use Admin\Api\VPostInfoApi;


/**
 *
 * 资讯查询接口
 * @author hebidu <hebiduhebi@126.com>
 * @date  15/12/5 10:28
 * @copyright by itboye.com
 */
class NewsDomain extends BaseDomain{

    protected $business_code = "news";

    protected $allowType = array("json", "rss", "html");

    /**
     * 资讯查询
     */
    public function query(){

        $notes = "应用" . $this->client_id ."调用资讯查询接口";
        addLog("News/query", $_GET, $_POST, $notes);
        //兼容2个版本，100，101
        $this->checkVersion(array(100,101));

        if(IS_POST){
            $position = $this -> _post('position','','缺少position参数');
            $page_no = $this -> _post('page_no',1);
            $page_size = $this -> _post('page_size',6);

            if($position == 'rd'){
                //返回六条最新信息
                $page = array(
                    'curpage' => 1,
                    'size' => 3,
                );
                $map = array(
                    'post_status'=>'publish',
                );
                $order = "post_date desc";
                $result = apiCall(VPostInfoApi::QUERY_WITH_COUNT,array($map,$page,$order));
                if($result['status']){
                    $this -> apiReturnSuc($result['info']);
                }else{
                    $this -> apiReturnErr($result['info']);
                }
            }else{
                if($position <= 0){
                    $this -> apiReturnErr('position参数错误');
                }
                $page = array(
                    'curpage'=>$page_no,
                    'size'=>$page_size,
                );
                $map = array(
                    'post_category' => $position,
                    'post_status'=>'publish',
                );
                $order = "post_date desc";

                $result = apiCall(VPostInfoApi::QUERY_WITH_COUNT,array($map,$page,$order));

                if($result['status']){
                    $this -> apiReturnSuc($result['info']);
                }else{
                    $this -> apiReturnErr($result['info']);
                }
            }

        }
    }

}